package com.hcbd.tdwt.ui.setting.xingyu.activity;
import android.annotation.SuppressLint;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;

import com.hcbd.tdwt.R;
import com.hcbd.tdwt.base.BaseActivity;
import com.hcbd.tdwt.ui.common.dialog.BottomSelectDialog;
import com.pangu.bdsdk2021.entity.terminaltwo.BDADXInfo;
import com.pangu.bdsdk2021.terminal.TerminalSendManager;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.SeekBarProgressChange;
import org.androidannotations.annotations.ViewById;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

@SuppressLint("NonConstantResourceId")
@EActivity(R.layout.activity_voice_parameter_set)
public class VoiceParameterActivity extends BaseActivity {
    @ViewById
    RelativeLayout playModeRL;
    @ViewById
    TextView roteTv;
    @ViewById
    SeekBar volumeSeekBar;
    private String playModeStr[]={"不播放","播放短信通知","播放短信通知和内容"};
    private Integer playModeValue[]={0,1,2};
    private BottomSelectDialog bottomSelectDialog;
    private HashMap<String,Integer>hashMap;
    private int currentMode=1;
    private boolean isInit=false;
    private boolean isRefresh=false;
    @AfterViews
    protected void init() {
        initMsgRegister();
        hashMap=new HashMap<>();
        hashMap.put(playModeStr[0],playModeValue[0]);
        hashMap.put(playModeStr[1],playModeValue[1]);
        hashMap.put(playModeStr[2],playModeValue[2]);
        List<String> str = Arrays.asList(playModeStr);
        bottomSelectDialog=new BottomSelectDialog(this, "选择播放模式", str, (index, str1) -> {
            roteTv.setText(str1);
            Integer mode=hashMap.get(str1);
            currentMode=mode;
           // int progress=volumeSeekBar.getProgress();
           // TerminalSendManager.getInstance().level_two_setCCADS(progress,mode);

        });

        TerminalSendManager.getInstance().level_two_getCCADQ();
    }
    @Click
    void playModeRL(){
        BottomSelectDialog.show(bottomSelectDialog);
    }
    @SeekBarProgressChange
    void volumeSeekBar(SeekBar seekBar, int progress, boolean fromUser){
       /* if(isInit) {
            TerminalSendManager.getInstance().level_two_setCCADS(progress, currentMode);
        }else{
            isInit=true;
        }*/
    }
    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true, priority = 1)
    public void eventBus(BDADXInfo bdadxInfo){
        try {
            volumeSeekBar.setProgress(Integer.parseInt(bdadxInfo.volume));
            roteTv.setText(playModeStr[Integer.parseInt(bdadxInfo.playMode)]);
            currentMode = Integer.parseInt(bdadxInfo.playMode);
            toast("加载成功！");
            if(isRefresh){
                finish();
            }
        }catch (Exception e){
            toast(e.getMessage());
        }
    }
    @Click
    void headLeft(){
        finish();
    }
    @Click
    void submitBtn(){
        isRefresh=true;
        int progress=volumeSeekBar.getProgress();
        TerminalSendManager.getInstance().level_two_setCCADS(progress, currentMode);

    }
}